package com.neardrug.controller;

import com.neardrug.common.Result;
import com.neardrug.context.BaseContext;
import com.neardrug.entity.Analysis;
import com.neardrug.services.AnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "文献提取结果相关")
@RequestMapping("/analysis")
public class AnalysisController {

    @Autowired
    private AnalysisService analysisService;

    @GetMapping
    @ApiOperation("获取该用户的所有结果列表")
    public Result selectAll(){
        Integer id = BaseContext.getCurrentId();//获取当前用户id
        List<Analysis> analysisList=analysisService.selectAll(id);
        return Result.success(analysisList);
    }

    /**
     * 根据任务id查询该任务的备注(notes)
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据任务id查询备注")
    public Result selectNotesById(@PathVariable Integer id){
        String notes=analysisService.selectNoteById(id);
        return Result.success(notes);
    }

    @PutMapping
    @ApiOperation("修改")
    public Result updateAnalysis(@RequestBody Analysis analysis){
        analysisService.updateAnalysis(analysis);
        return Result.success();
    }

    @GetMapping("/collect")
    @ApiOperation("查询该用户收藏的结果列表")
    public Result selectCollected(){
        Integer id = BaseContext.getCurrentId();
        List<Analysis> analysisList=analysisService.selectCollected(id);
        return Result.success(analysisList);
    }
}
